.<HTML>
<HEAD>
<TITLE>JavaScript Source Code 3000:  Games:  Reaction Time - BG</TITLE>
<META HTTP-EQUIV="JavaScript Source Code 3000" CONTENT = "no-cache">
<META NAME="date" CONTENT="2000-09-09">
<META NAME="channel" CONTENT="Web Developer">
<META NAME="author" CONTENT="Jasper van Zandbeek">
<META NAME="section" CONTENT="Games">
<META NAME="description" CONTENT="(Netscape only)  Just how fast can you react?  Play this little JavaScript wonder and find out.  In this example, you react when the background changes color instead of dealing with a button.">

<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
var startTime=new Date();
var endTime=new Date();
var startPressed=false;
var bgChangeStarted=false;
var maxWait=20;
var timerID;
function startTest() {
document.bgColor=document.response.bgColorChange.options[document.response.bgColorChange.selectedIndex].text;
bgChangeStarted=true;
startTime=new Date();
}
function remark(responseTime) {
var responseString="";
if (responseTime < 0.10)
responseString="Well done!";
if (responseTime >= 0.10 && responseTime < 0.20)
responseString="Nice!";
if (responseTime >=0.20 && responseTime < 0.30)
responseString="Could be better...";
if (responseTime >=0.30 && responseTime < 0.60)
responseString="Keep practicing!";
if (responseTime >=0.60 && responseTime < 1)
responseString="Have you been drinking?";
if (responseTime >=1)
responseString="Did you fall asleep?";
return responseString;
}
function stopTest() {
if(bgChangeStarted) {
endTime=new Date();
var responseTime=(endTime.getTime()-startTime.getTime())/1000;
document.bgColor="white";       
alert("Your response time is: " + responseTime + " seconds " + "\n" + remark(responseTime));
startPressed=false;
bgChangeStarted=false;
}
else
{
if (!startPressed) {
alert("press start first to start test");
}
else
{       
clearTimeout(timerID);
startPressed=false;             
alert("cheater! you pressed too early!");
      }               
   }
}
var randMULTIPLIER=0x015a4e35;
var randINCREMENT=1;
var today=new Date();
var randSeed=today.getSeconds();
function randNumber() {
randSeed = (randMULTIPLIER * randSeed + randINCREMENT) % (1 << 31);
return((randSeed >> 15) & 0x7fff) / 32767;
}
function start() {
if(startPressed) {
alert("Already started. Press stop to stop");
return;
}
else
{
startPressed=true; 
timerID=setTimeout('startTest()', 20000*randNumber());
   }
}
// End --> 
</SCRIPT>
</HEAD>

<BODY BGCOLOR=#ffffff vlink=#0000ff>

<BR>
<center>
<table width="600" cellpadding="0" cellspacing="10">
<tr>
<td width="468" align="center">

	
</td>
<td width="120" align="center">

	
</td>
</tr>
</table>
<BR>
<BR>
<BASEFONT SIZE=3>
  <FONT SIZE=6>
<B><FONT SIZE="+2" FACE="Helvetica,Arial" ALIGN=RIGHT COLOR="#0000FF">
<b><A HREF="../index.htm" /" TARGET="_top">
Home</A> </b><img src="../img/arrow.gif" /img/arrow.gif" height=13 width=7 border=0 alt="}"> <b><A HREF="index.htm" /games/"><font color="#FF0000">Games</font></A> </b>
<img src="../img/arrow.gif" /img/arrow.gif" height=13 width=7 border=0 alt="}"> <FONT COLOR="#006666">French Translator</FONT></b></FONT><BR>
</B><BR>
  </FONT>
<table BORDER=0 WIDTH=486 CELLPADDING=3 CELLSPACING=0>
<tr><td><font FACE="helvetica,arial,geneva">
<br>
<br>
<!-- Description --><!--content_start-->

(Netscape only)  Just how fast can you react?  Play this little JavaScript wonder and find out.  In this example, you react when the background changes color instead of dealing with a button.
<hr>
</td></tr>
</table>
<!-- Demonstration -->
<BODY>
<CENTER>
<FORM name="response">
Change background color to: 
<SELECT name="bgColorChange">
<option selected>deeppink
<option>aliceblue
<option>crimson
<option>darkkhaki
<option>cadetblue
<option>darkorchid
<option>coral
<option>chocolate
<option>mediumslateblue
<option>tomato
<option>darkslategray
<option>limegreen
<option>cornflowerblue
<option>darkolivegreen
</SELECT>
<input type="button" value="start" onClick="start()">
<input type="button" value="stop" onClick="stopTest()">
</FORM>
<P>
<P>
<a name="source">
<table BORDER=0 WIDTH=486 CELLPADDING=3 CELLSPACING=0>
<tr><td BGCOLOR=yellow><font FACE="helvetica,arial,geneva"><b>JavaScript Source Code 3000:  Games:  Reaction - BG</b>
<p>Simply click inside the window below, use your cursor to highlight the script, and copy (type Control-c or Apple-c) the script into a new file in your text editor (such as Note Pad or Simple Text) and save (Control-s or Apple-s).  The script is yours!!!<br><br></font></td></tr>
<tr><td BGCOLOR=yellow ALIGN=CENTER>
<form NAME="copy">

<DIV align="center">
<input type=button value="Highlight All" onClick="javascript:this.form.txt.focus();this.form.txt.select();">&nbsp;&nbsp;&nbsp;&nbsp;
<INPUT TYPE="text" NAME="total" VALUE="Script Size:  2.91 KB  " size="24">
</DIV>

<textarea NAME="txt" ROWS=20 COLS=75 WRAP=VIRTUAL>

&lt;!-- TWO STEPS TO INSTALL REACTION - BG:

   1.  Put the designated coding into the HEAD of your HTML document
   2.  Put the last coding into the BODY of your HTML document  --&gt;

&lt;!-- STEP ONE: Copy this code into the BODY of your HTML document  --&gt;

&lt;HEAD&gt;

&lt;SCRIPT LANGUAGE="JavaScript"&gt;
&lt;!-- Original:  Jasper van Zandbeek --&gt;

&lt;! &gt;
&lt;! &gt;

&lt;!-- Begin
var startTime=new Date();
var endTime=new Date();
var startPressed=false;
var bgChangeStarted=false;
var maxWait=20;
var timerID;
function startTest() {
document.bgColor=document.response.bgColorChange.options[document.response.bgColorChange.selectedIndex].text;
bgChangeStarted=true;
startTime=new Date();
}
function remark(responseTime) {
var responseString="";
if (responseTime &lt; 0.10)
responseString="Well done!";
if (responseTime &gt;= 0.10 && responseTime &lt; 0.20)
responseString="Nice!";
if (responseTime &gt;=0.20 && responseTime &lt; 0.30)
responseString="Could be better...";
if (responseTime &gt;=0.30 && responseTime &lt; 0.60)
responseString="Keep practicing!";
if (responseTime &gt;=0.60 && responseTime &lt; 1)
responseString="Have you been drinking?";
if (responseTime &gt;=1)
responseString="Did you fall asleep?";
return responseString;
}
function stopTest() {
if(bgChangeStarted) {
endTime=new Date();
var responseTime=(endTime.getTime()-startTime.getTime())/1000;
document.bgColor="white";       
alert("Your response time is: " + responseTime + " seconds " + "\n" + remark(responseTime));
startPressed=false;
bgChangeStarted=false;
}
else
{
if (!startPressed) {
alert("press start first to start test");
}
else
{       
clearTimeout(timerID);
startPressed=false;             
alert("cheater! you pressed too early!");
      }               
   }
}
var randMULTIPLIER=0x015a4e35;
var randINCREMENT=1;
var today=new Date();
var randSeed=today.getSeconds();
function randNumber() {
randSeed = (randMULTIPLIER * randSeed + randINCREMENT) % (1 &lt;&lt; 31);
return((randSeed &gt;&gt; 15) & 0x7fff) / 32767;
}
function start() {
if(startPressed) {
alert("Already started. Press stop to stop");
return;
}
else
{
startPressed=true; 
timerID=setTimeout('startTest()', 20000*randNumber());
   }
}
// End --&gt; 
&lt;/SCRIPT&gt;

&lt;!-- STEP TWO:  Put this last coding into the BODY of your HTML document --&gt;

&lt;BODY&gt;

&lt;CENTER&gt;
&lt;FORM name="response"&gt;
Change background color to: 
&lt;SELECT name="bgColorChange"&gt;
&lt;option selected&gt;deeppink
&lt;option&gt;aliceblue
&lt;option&gt;crimson
&lt;option&gt;darkkhaki
&lt;option&gt;cadetblue
&lt;option&gt;darkorchid
&lt;option&gt;coral
&lt;option&gt;chocolate
&lt;option&gt;mediumslateblue
&lt;option&gt;tomato
&lt;option&gt;darkslategray
&lt;option&gt;limegreen
&lt;option&gt;cornflowerblue
&lt;option&gt;darkolivegreen
&lt;/SELECT&gt;
&lt;input type="button" value="start" onClick="start()"&gt;
&lt;input type="button" value="stop" onClick="stopTest()"&gt;
&lt;/FORM&gt;
&lt;/CENTER&gt;

 

&lt;!-- Script Size:  2.91 KB  --&gt;
</textarea><br><font FACE="helvetica,arial,geneva"></font></td></tr>

</table>
</form>
</FONT>
</CENTER>


</center>
</body></html>